﻿using Microsoft.AspNetCore.Mvc;
using System;
using Think9.Models;

namespace Think9.Controllers.Basic
{
    public class ButtonController : BaseController
    {
        //直接使用基类BaseController的ButtonService
        // GET: Permissions/Button
        public override ActionResult Index(int? id)
        {
            base.Index(id);
            return View();
        }

        [HttpGet]
        public JsonResult List(ButtonEntity model, PageInfoEntity pageInfo)
        {
            var result = ButtonService.GetListByFilter(model, pageInfo);
            return Json(result);
        }

        public ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Add(ButtonEntity model)
        {
            model.UpdateTime = DateTime.Now;
            var result = ButtonService.Insert(model) ? SuccessTip("操作成功") : ErrorTip("操作失败");
            return Json(result);
        }

        public ActionResult Edit(int id)
        {
            var model = ButtonService.GetById(id);
            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(ButtonEntity model)
        {
            model.UpdateTime = DateTime.Now;
            var result = ButtonService.UpdateById(model) ? SuccessTip("操作成功") : ErrorTip("编辑失败");
            return Json(result);
        }

        [HttpGet]
        public JsonResult Delete(int id)
        {
            var result = ButtonService.DeleteById(id) ? SuccessTip("删除成功") : ErrorTip("操作失败");
            return Json(result);
        }
    }
}